from pytest import mark
import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

class TestLogin:
    def setup_method(self):  # 用setup_method而非setup，更规范
        # 初始化驱动（指定匹配的ChromeDriver版本）
        self.driver = webdriver.Chrome(
            service=Service(ChromeDriverManager().install())# 替换为你的版本
        )
        self.driver.maximize_window()
        self.driver.implicitly_wait(10)

    def teardown_method(self):  # 每个用例结束后关闭驱动
        self.driver.quit()

    @pytest.mark.test
    def test_login(self):
        target_url = "http://192.168.66.162:20080/login?redirect=%2Findex"
        self.driver.get(target_url)
        # 可添加后续操作，比如定位用户名密码输入框
        # username = WebDriverWait(self.driver, 10).until(
        #     EC.visibility_of_element_located((By.ID, "username"))
        # )
        # username.send_keys("admin")

if __name__ == '__main__':
    pytest.main(["-v", __file__])  # 用pytest运行，而非直接调用方法